package org.pettyfox.pfpay.controller.api;

import org.pettyfox.pfpay.biz.PayAloneRealPayBiz;
import org.pettyfox.pfpay.biz.PayOrderBiz;
import org.pettyfox.pfpay.msg.ObjectResponse;
import org.pettyfox.pfpay.pojo.api.Pay;
import org.pettyfox.pfpay.pojo.api.PayAlonePojo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
public class PayRest {
    @Resource
    PayAloneRealPayBiz payAloneRealPayBiz;
    @Resource
    PayOrderBiz payOrderBiz;
    /**
     * 返回支付信息，并且创建订单
     * @param pay
     * @return
     */
    @PostMapping("pay")
    public ObjectResponse pay(@RequestBody Pay pay){
        //获取支付信息
        PayAlonePojo payAlone = payAloneRealPayBiz.getPayAlone(pay.getUid(),pay.getBehoovePrice(),pay.getType());
        if(null == payAlone){
            return null;
        }
        payOrderBiz.createWaitPayOrder(pay,payAlone);

        return ObjectResponse.ok(payAlone);
    }
    /**
     * 订单审核
     * @param id
     * @return
     */
    @PutMapping("payAudit/{id}")
    public ObjectResponse payAudit(Long id){
        //获取支付信息
       payOrderBiz.updateStatusToWaitAudit(id);

        return ObjectResponse.ok("");
    }
}
